home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-11-25 | 1.2 KB | 45 lines |
- // Motd.java
- // This program checks if file exists or not.
- import vrml.*;
- import vrml.node.*;
- import vrml.field.*;
- import java.io.*;
-
- public class Motd extends Script {
- String myFile = "C:/tmp/motd"; // message of today
- Browser b;
- DataInputStream in;
- String message;
-
- public void initialize() {
- b = getBrowser(); // to display error message
- }
-
- public void processEvent(Event ev){
- File f = null;
- // open file
- if(ev.getName().equals("clicked")){
- try {
- f = new File(myFile);
- in = new DataInputStream(new FileInputStream(f));
- } catch (Exception e){
- b.setDescription("can not open file: " + myFile);
- e.printStackTrace();
- }
-
- // if it exists, read it
- try {
- if(f.exists()){
- message = in.readLine();
- // display the message of today.
- b.setDescription(message);
- } else {
- b.setDescription("file does not exists: " + myFile);
- }
- } catch (Exception e){
- e.printStackTrace();
- }
- }
- }
- }
-